'''
添加部门页面
'''
from selenium.webdriver.common.by import By
from page.base_page import BasePage
from selenium.webdriver.support.select import Select

class AddDepartmentPage(BasePage):
    # 定位器
    bumenming_locator = (By.ID, 'name')
    shangjibumen_locator = (By.NAME, 'parent_id')
    miaoshu_locator = (By.XPATH, '//*[@id="department_add"]/div[3]/div/textarea')

    queren_btn_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]')
    quxiao_btn_locator = (By.XPATH,
                          '/html/body/div[8]/div[3]/div/button[2]')
    tiaozhuan_duanyan_locator = (By.ID,'ui-id-5')
    tianjia_duanyan_locator = (By.XPATH,'/html/body/div[5]/div[2]')


    # 输入部门名
    def tjbm_bmm(self, name):
        self.driver.find_element(*self. bumenming_locator).send_keys(name)

    # 选择上级部门
    def tjbm_sjbm(self):
        sjbm = self.driver.find_element(*self.shangjibumen_locator)
        Select(sjbm).select_by_index(1)

        # 输入部门描述
    def tjbm_bmms(self, bmms):
        self.driver.find_element(*self.miaoshu_locator).send_keys(bmms)

        # 点击确认
    def tjbm_queren(self):
        self.driver.find_element(*self.queren_btn_locator).click()

        # 点击取消
    def tjbm_quxiao(self):
        self.driver.find_element(*self.quxiao_btn_locator).click()

# 断言跳转
    def tjbm_duanyan_into(self):
        return self.driver.find_element(*self.tiaozhuan_duanyan_locator).text
# 断言添加
    def tjbm_duanyan_tianjia(self):
        return self.driver.find_element(*self.tianjia_duanyan_locator).text
# 断言弹窗取消
    def tjbm_duanyan_quxiaotankuang(self):
        try:
            self.driver.tjbm_queren()
        except:
            baocuoxinxi = "报错"
            return baocuoxinxi